import { LayerTypeFE, LayerTypeBE } from '../../../../../../../constant';
import { useMemo } from 'react';

export const useHasImage = (type: LayerTypeBE): boolean => {
  return useMemo(() => {
    return type === LayerTypeBE.Image;
  }, [type]);
};

export const useHasProductImage = (type: LayerTypeBE): boolean => {
  return useMemo(() => {
    return type === LayerTypeBE.Product;
  }, [type]);
};

export const useHasShapes = (type: LayerTypeBE): boolean => {
  return useMemo(() => {
    return type === LayerTypeBE.Shape;
  }, [type]);
};

export const useHasCorner = (
  type: LayerTypeBE,
  subType: LayerTypeFE
): boolean => {
  return useMemo(() => {
    // text 图层或者矩形和三角形的 shape 图层需要有圆角配置
    return (
      type === LayerTypeBE.Text ||
      (type === LayerTypeBE.Shape &&
        [LayerTypeFE.Rect, LayerTypeFE.Triangular].includes(subType))
    );
  }, [type, subType]);
};

export const useHasColor = (
  type: LayerTypeBE,
  subType: LayerTypeFE
): {
  hasFillColor: boolean;
  hasBorderColor: boolean;
} => {
  return useMemo(() => {
    const hasFillColor =
      type === LayerTypeBE.Text ||
      (type === LayerTypeBE.Shape && subType !== LayerTypeFE.Line);

    const hasBorderColor = type === LayerTypeBE.Shape;
    return {
      hasFillColor,
      hasBorderColor
    };
  }, [type, subType]);
};

export const useHasText = (type: LayerTypeBE): boolean => {
  return useMemo(() => {
    return type === LayerTypeBE.Text;
  }, [type]);
};
